package com.xmlstrategys
{
	import com.adobe.serialization.json.JSON;
	import com.strategy.IXML;
	import com.utils.Utils;
	
	import flash.utils.ByteArray;
	
	public class XMLCadornInfo extends XMLBase implements IXML
	{
		public function XMLCadornInfo(data:XML)
		{
			super(data);
		}
		
		public function xmlstrategybml():ByteArray
		{
			var sourceByte:ByteArray = Utils.writeHead(8);
			var nodeLen:uint = xmlData.bonus.length();
			sourceByte.writeUnsignedInt(nodeLen);
			
			for each (var xml:XML in xmlData.bonus){
				sourceByte.writeUnsignedInt(xml.@ItemTemplateId);
				writeList(xml.@Attack,sourceByte);
				writeList(xml.@Deffence,sourceByte);
				writeList(xml.@Hit,sourceByte);
				writeList(xml.@Dodge,sourceByte);
				writeList(xml.@CriticalDamage,sourceByte);
				writeList(xml.@CriticalRate,sourceByte);
				writeList(xml.@SkillHit,sourceByte);
				writeList(xml.@SkillDodge,sourceByte);
				writeList(xml.@Hp,sourceByte);
				writeList(xml.@Mp,sourceByte);
				writeList(xml.@Resistance1,sourceByte);
				writeList(xml.@Resistance2,sourceByte);
				writeList(xml.@Resistance3,sourceByte);
				writeList(xml.@Resistance4,sourceByte);
				writeList(xml.@Resistance5,sourceByte);
				writeList(xml.@CrtrateReduce,sourceByte);
				writeList(xml.@CrtdmgReduce,sourceByte);
				writeList(xml.@DamageReduce,sourceByte);
			}
			
			return sourceByte;
		}
		
		private function writeList(str:String,byteArray:ByteArray):void
		{
			var list:Array = JSON.decode(str) as Array;
			var listLen:int = list.length;
			var index:int=0;
			while(index<listLen)
			{
				byteArray.writeUnsignedInt(list[index]);
				index++;
			}
		}
	}
}